import {
  defHttp
} from '/@/utils/http/axios';
import {
  useMessage
} from "/@/hooks/web/useMessage";
import {
  ApiOutlined
} from '@ant-design/icons-vue';

const {
  createConfirm
} = useMessage();

enum Api {
  list = '/ps/psProductProcess/list',
    save = '/ps/psProductProcess/add',
    edit = '/ps/psProductProcess/edit',
    deleteOne = '/ps/psProductProcess/delete',
    deleteBatch = '/ps/psProductProcess/deleteBatch',
    importExcel = '/ps/psProductProcess/importExcel',
    exportXls = '/ps/psProductProcess/exportXls',
    psProductProcessTechnicList = '/ps/psProductProcess/queryPsProductProcessTechnicByMainId',
    queryBomMaterial = '/base/materialBom/queryBomMaterial',
    materialList = '/base/material/list',
    unitList = '/base/unit/list',
    exportXlsTemplate = '/ps/psProductProcess/exportXlsTemplate',
    queryById = '/ps/psProductProcess/queryById',
    basResourceGroupDefinitionItemList = '/base/resourceGroupDefinition/queryBasResourceGroupDefinitionItemByMainId',
}
/**
 * 导出模板api
 * @param params
 */
export const exportXlsTemplate = Api.exportXlsTemplate;
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 查询子表数据
 * @param params
 */
export const basResourceGroupDefinitionItemList = (params) => defHttp.get({url: Api.basResourceGroupDefinitionItemList,params});
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

// 单位
export const unitList = (params) =>
  defHttp.get({
    url: Api.unitList,
    params
  });
/**
 * 料品管理-分页列表查询
 * @param params
 */
export const getMaterialList = (params) =>
  defHttp.get({
    url: Api.materialList,
    params
  });
/**
 * 产品BOM-根据产品ID递归查询BOM结构树所对应的料品，以列表方式展现
 * @param params
 */
export const getQueryBomMaterial = (params) =>
  defHttp.get({
    url: Api.queryBomMaterial,
    params
  });
/**
 * 查询子表数据
 * @param params
 */
export const psProductProcessTechnicList = Api.psProductProcessTechnicList;
// 查询详情
export const getQueryById = (params) =>
  defHttp.get({
    url: Api.queryById,
    params
  });
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({
    url: Api.list,
    params
  });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({
    url: Api.deleteOne,
    params
  }, {
    joinParamsToUrl: true
  }).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({
        url: Api.deleteBatch,
        data: params
      }, {
        joinParamsToUrl: true
      }).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({
    url: url,
    params
  });
}
